package com.xintonghua.bussiness.ui.home;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.xintonghua.base.widget.ShowAllListView;
import com.xintonghua.bussiness.R;
import com.xintonghua.bussiness.base.BaseFragment;
import com.xintonghua.bussiness.bean.TaskBean;
import com.xintonghua.bussiness.bean.TaskBeans;
import com.xintonghua.bussiness.util.AbstractBaseAdapter;
import com.xintonghua.bussiness.util.GlideUtils;
import com.xintonghua.bussiness.util.MyUtils;
import com.xintonghua.bussiness.util.ViewHolder;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * Created by liqi on 2018/4/1.
 */

public class TaskFragment extends BaseFragment {
    @BindView(R.id.lv_list)
    ListView lvList;
    Unbinder unbinder;

    @Override
    public int getLayout() {
        return R.layout.fragment_task_item;
    }

    List<TaskBeans.ProjectListBean> projectListBeans;
    List<TaskBean.ServiceListBean> serviceListBeans;
    String type;

    @Override
    public void initUI(View rootView) {
        unbinder = ButterKnife.bind(this, rootView);
        projectListBeans = (List<TaskBeans.ProjectListBean>) getArguments().getSerializable("data0");
        serviceListBeans = (List<TaskBean.ServiceListBean>) getArguments().getSerializable("data1");

//        projectListBeans = new ArrayList<>();
//        serviceListBeans = new ArrayList<>();
        type = getArguments().getString("type");
        switch (type) {
            case "0":
                Log.i("aaa", "运行了着0");
                setAdapter0();
                break;
            case "1":
                Log.i("aaa", "运行了着1");
                setAdapter1();
                break;
        }


    }

    public void setAdapter0() {
        lvList.setAdapter(new AbstractBaseAdapter<TaskBeans.ProjectListBean>(projectListBeans) {

            @Override
            public View getAdapterViewAtPosition(int position, View convertView, ViewGroup parent) {
                TaskBeans.ProjectListBean bean = getItem(position);
                if (convertView == null) {
                    convertView = LayoutInflater.from(getActivity()).inflate(R.layout.fragment_layout_adapter, null);
                }
                TextView tvProduct = ViewHolder.get(convertView, R.id.tv_product);
                ImageView ivUserHead = ViewHolder.get(convertView, R.id.iv_user_head);
                TextView tvName = ViewHolder.get(convertView, R.id.tv_name);
                TextView tvPhone = ViewHolder.get(convertView, R.id.tv_phone);
                TextView tvTime = ViewHolder.get(convertView, R.id.tv_time);
                TextView tvTimeTag = ViewHolder.get(convertView, R.id.tv_time_tag);
                ShowAllListView salListview = ViewHolder.get(convertView, R.id.sal_listview);
                if (bean.getUseType().equals("member")) {
                    tvProduct.setText("会员卡");
                } else if (bean.getUseType().equals("product")) {
                    tvProduct.setText("产品");
                } else if (bean.getUseType().equals("service")) {
                    tvProduct.setText("项目");
                }

                TextView tv_service = ViewHolder.get(convertView, R.id.tv_service);
                TextView tv_number = ViewHolder.get(convertView, R.id.tv_number);
                TextView tv_prices = ViewHolder.get(convertView, R.id.tv_prices);
                tv_service.setText("" + bean.getName());
                tv_number.setText("" + bean.getNumber());
                tv_prices.setText("¥" + bean.getPrice());
                GlideUtils.loadCricle(getActivity(), ivUserHead, bean.getHead_img());
                tvName.setText("" + bean.getNickname());
                tvPhone.setText("" + bean.getPhone());
                tvTime.setText("" + bean.getCreate_time());

                return convertView;
            }
        });
    }

    public void setAdapter1() {
        lvList.setAdapter(new AbstractBaseAdapter<TaskBean.ServiceListBean>(serviceListBeans) {

            @Override
            public View getAdapterViewAtPosition(int position, View convertView, ViewGroup parent) {

                Log.i("aaa", "setAdapter1");
                TaskBean.ServiceListBean bean = getItem(position);
                if (convertView == null) {
                    convertView = LayoutInflater.from(getActivity()).inflate(R.layout.fragment_layout_adapter, null);
                }
                TextView tvProduct = ViewHolder.get(convertView, R.id.tv_product);
                ImageView ivUserHead = ViewHolder.get(convertView, R.id.iv_user_head);
                TextView tvName = ViewHolder.get(convertView, R.id.tv_name);
                TextView tvPhone = ViewHolder.get(convertView, R.id.tv_phone);
                TextView tvTime = ViewHolder.get(convertView, R.id.tv_time);
                TextView tvTimeTag = ViewHolder.get(convertView, R.id.tv_time_tag);
                ShowAllListView salListview = ViewHolder.get(convertView, R.id.sal_listview);

                TextView tv_service = ViewHolder.get(convertView, R.id.tv_service);
                TextView tv_number = ViewHolder.get(convertView, R.id.tv_number);
                TextView tv_prices = ViewHolder.get(convertView, R.id.tv_prices);
                if (bean.getUseType().equals("member")) {
                    tvProduct.setText("会员卡");
                } else if (bean.getUseType().equals("product")) {
                    tvProduct.setText("产品");
                } else if (bean.getUseType().equals("service")) {
                    tvProduct.setText("项目");
                }

                tv_service.setText("" + bean.getName());
                tv_number.setText("" + bean.getCOUNT());
                tv_prices.setText("¥" + bean.getMoney());
                GlideUtils.loadCricle(getActivity(), ivUserHead, bean.getHead_img());
                tvName.setText("" + bean.getNickname());
                tvPhone.setText("" + bean.getPhone());
                tvTime.setText("" + bean.getCreate_time());
                return convertView;
            }
        });
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }


}
